#ifndef _COM_BOSE_AUDIO_PLAYER_H_
#define _COM_BOSE_AUDIO_PLAYER_H_

#include <stdio.h>
#include <stdlib.h>
#include <string>

#define STRINGIZE(x) #x


namespace com {
namespace bose {

enum PlayStatus {
    PLAY_STATUS_DEFAULT = 0,
    PLAY_STATUS_PLAYING = 1,
    PLAY_STATUS_STOPPED = 2,
    PLAY_STATUS_ERROR = 3,
};

enum ErrorCode {
    AP_ERRORCODE_RETRY = -5,
    AP_ERRORCODE_UNKNOWN = -4,
    AP_ERRORCODE_SYSTEM_ERROR = -3,
    AP_ERRORCODE_INVALID_ARGUMENTS = -2,
    AP_ERRORCODE_INVALID_STATUS = -1,
    AP_ERRORCODE_OK = 0
};

static const char* error2str (ErrorCode err) {
    switch(err){
    case AP_ERRORCODE_RETRY:
        return STRINGIZE(AP_ERRORCODE_RETRY);
    case AP_ERRORCODE_UNKNOWN:
        return STRINGIZE(AP_ERRORCODE_UNKNOWN);
    case AP_ERRORCODE_SYSTEM_ERROR:
        return STRINGIZE(AP_ERRORCODE_SYSTEM_ERROR);
    case AP_ERRORCODE_INVALID_ARGUMENTS:
        return STRINGIZE(AP_ERRORCODE_INVALID_ARGUMENTS);
    case AP_ERRORCODE_INVALID_STATUS:
        return STRINGIZE(AP_ERRORCODE_INVALID_STATUS);
    case AP_ERRORCODE_OK:
        return STRINGIZE(AP_ERRORCODE_OK);
    default:
        return "";
    }
}
static const char* status2str(PlayStatus status) {
    switch(status){
    case PLAY_STATUS_DEFAULT:
        return STRINGIZE(PLAY_STATUS_DEFAULT);
    case PLAY_STATUS_PLAYING:
        return STRINGIZE(PLAY_STATUS_PLAYING);
    case PLAY_STATUS_STOPPED:
        return STRINGIZE(PLAY_STATUS_STOPPED);
    case PLAY_STATUS_ERROR:
        return STRINGIZE(PLAY_STATUS_ERROR);
    default:
        return "";
    }
}

/* use child process id as  session id.
   the session_id can be used by app to stop the child process*/
typedef int session_id;

#define AP_SESSION_ID_INVALID (-1)

#define AP_SIGNAL_PLAY_STATUS (55)
#define AP_SIGNAL_CONTROL_PAUSE (56)
#define AP_SIGNAL_CONTROL_SEEK (57)

#define AP_SIGNAL_FRAME_COUNT (60)
#define AP_SIGNAL_CURRENT_SECONDS (61)


class AudioPlayer {
public:
    virtual ~AudioPlayer();
    AudioPlayer(const std::string url);
    session_id play();
    ErrorCode stop(session_id id);
    ErrorCode pause(session_id id, bool pause);
    ErrorCode seek(int32_t seconds);
    PlayStatus ap_get_status();
    void ap_set_status(PlayStatus);

protected:
    const std::string mUrl;

private:
    AudioPlayer() = delete;
};

} //namespace bose
} //namespace com
#endif //endif _COM_BOSE_AUDIO_PLAYER_H_